home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / r2_hello.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  2KB  |  107 lines

  1. {$X+,V-,B-}
  2. program RecHello2;
  3.  
  4. { Simple IPX demonstration program, that uses one receive ESR.
  5.  
  6.   Run this program on 1 workstation, run S_HELLO or S1_HELLO on another.
  7.   S_HELLO will send "hello world" messages,
  8.   this workstation will receive them.  }
  9.  
  10. uses crt,nwMisc,nwIPX;
  11.  
  12. CONST IOSocket=$5678;
  13.  
  14. Var ReceiveEcb    :Tecb;
  15.     IpxHdr        :TipxHeader;
  16.     socket        :word;
  17.     buf           :array[1..546] of byte;
  18.     t             :byte;
  19.     ReceivedBufLen:word;
  20.     PacketReceived:boolean;
  21.  
  22.     RecString     :string;
  23.  
  24.     NewStack:array[1..1024] of word;  { !! used by ESR }
  25.     StackBottom:word;                 { !! used by ESR }
  26.  
  27.  
  28. {$F+}
  29. Procedure ListenESRhandler(Var p:Tpecb);
  30. begin
  31. RecString[0]:=chr(p^.fragment[2].size);
  32. move(p^.fragment[2].address^,RecString[1],byte(RecString[0]));
  33. PacketReceived:=true;
  34. IPXListenForPacket(ReceiveECB);
  35. end;
  36. {$F-}
  37.  
  38. {$F+}
  39. Procedure ListenESR; assembler;
  40. asm { ES:SI are the only valid registers when entering this procedure ! }
  41.     mov dx, seg stackbottom
  42.     mov ds, dx
  43.  
  44.     mov dx,ss  { setup of a new local stack }
  45.     mov bx,sp  { ss:sp copied to dx:bx}
  46.     mov ax,ds
  47.     mov ss,ax
  48.     mov sp,offset stackbottom
  49.     push dx    { push old ss:sp on new stack }
  50.     push bx
  51.  
  52.     push es    { push es:si on stack as local vars }
  53.     push si
  54.     mov  di,sp
  55.  
  56.     push ss    { push address of local ptr on stack }
  57.     push di
  58.     CALL ListenEsrHandler
  59.  
  60.     add sp,4   { skip stack ptr-copy }
  61.     pop bx     { restore ss:sp from new stack }
  62.     pop dx
  63.     mov sp,bx
  64.     mov ss,dx
  65. end;
  66. {$F-}
  67.  
  68.  
  69. begin
  70. IF NOT IpxInitialize
  71.  then begin
  72.       writeln('Ipx needs to be installed.');
  73.       halt(1);
  74.       end;
  75. socket:=IOSocket;
  76. IF NOT IPXopenSocket(Socket,SHORT_LIVED_SOCKET)
  77.  then begin
  78.       writeln('IPXopenSocket returned error# ',nwIPX.result);
  79.       halt(1);
  80.       end;
  81.  
  82. PacketReceived:=False;
  83. { Empty receive buffer (ReceiveEcb.fragment[2].address^) }
  84. FillChar(buf,546,#0);
  85.  
  86. { Setup ECB and IPX header }
  87. IPXsetupListenECB(Addr(ListenESR),IOsocket,@buf,546,
  88.                   IpxHdr,ReceiveEcb);
  89.  
  90. IPXListenForPacket(ReceiveECB);
  91.  
  92. REPEAT
  93.  
  94. IPXrelinquishControl;
  95.  
  96. IF PacketReceived { ESR has signalled that a packet has been received }
  97.  then begin
  98.       writeln(RecString);
  99.       PacketReceived:=false;
  100.       end;
  101.  
  102. UNTIL KeyPressed;
  103.  
  104. IF NOT IPXcloseSocket(IOsocket)
  105.  then writeln('IPXcloseSocket returned error# ',nwIPX.result);
  106.  
  107. end.